package poketrade.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Date;

import javax.persistence.*;

import poketrade.utils.SHA1;

@Entity
@NamedQueries( { @NamedQuery(name="queryLogin", query="SELECT u FROM User u WHERE u.pseudo = :pseudo AND u.password = :password"),
@NamedQuery(name="queryAllUsers", query="SELECT u FROM User u")})
//Table User is reserved in pgsql
@Table(name="SiteUser")
public class User implements Serializable {
	
	private static final long serialVersionUID = 3344434620085542161L;

	@Id
	@GeneratedValue
	private long id;
	
	private String pseudo;
	private String nom;
	private String prenom;
	private String email;
	private String password;
	private Date dateNaissance;
	private String adresse;
	private String departement;
	private String ville;
	private int cote;
	private Boolean premium;
	private Boolean admin;
	private float solde;
	
	@OneToMany(fetch=FetchType.LAZY)
	//@Cascade()
	private List<PendingOffer> offers;
	
	public User()
	{
		offers = new ArrayList<PendingOffer>();
	}
	
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getPseudo() {
		return pseudo;
	}
	public void setPseudo(String pseudo) {
		this.pseudo = pseudo;
	}
	public String getPassword() {
		return password;
	}
	public String getNom() {
		return nom;
	}
	public void setNom(String nom) {
		this.nom = nom;
	}
	public String getPrenom() {
		return prenom;
	}
	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}
	public String getDepartement() {
		return departement;
	}
	public void setDepartement(String departement) {
		this.departement = departement;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public void setSha1Password(String password) {
		this.password = SHA1.encode(password);
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public Date getDateNaissance() {
		return dateNaissance;
	}
	public void setDateNaissance(Date dateNaissance) {
		this.dateNaissance = dateNaissance;
	}
	public String getAdresse() {
		return adresse;
	}
	public void setAdresse(String adresse) {
		this.adresse = adresse;
	}
	public String getVille() {
		return ville;
	}
	public void setVille(String ville) {
		this.ville = ville;
	}
	public int getCote() {
		return cote;
	}
	public void setCote(int cote) {
		this.cote = cote;
	}
	public Boolean getPremium() {
		return premium;
	}
	public void setPremium(Boolean premium) {
		this.premium = premium;
	}
	public Boolean getAdmin() {
		return admin;
	}
	public void setAdmin(Boolean admin) {
		this.admin = admin;
	}
	public List<PendingOffer> getOffers() {
		return offers;
	}
	public void addOffer(PendingOffer o)
	{
		offers.add(o);
	}

	public float getSolde() {
		return solde;
	}

	public void setSolde(float solde) {
		this.solde = solde;
	}
}
